/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gestion;

import com.mysql.jdbc.Driver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
import java.util.Random;

/**
 *
 * @author BENAMMAR Riyadh
 */
/**
 * Cette classe est faite pour enrichir les bases de données
 *
 * @author BENAMMAR Riyadh
 */
public class Enrichissement {

    private static ResultSet result;

    public static void main(String[] args) {
        try {
            /*com.mysql.jdbc.Driver driver=new Driver();
            
             String url = "jdbc:mysql://localhost:3306/billetterie";
             String user = "root";
             String passwd = "";
             Properties p=new Properties();
             p.setProperty("user", user);
             p.setProperty("password", passwd);
      
             Connection conn = driver.connect(url, p);
             System.out.println("Connexion effective !");    
             Statement state=conn.createStatement();
      
             for(int i=1;i<500;i++){
             int itineraire=new Random().nextInt(199)+1;
             result=state.executeQuery("select * from reservation where id_itineraire="+itineraire);
             ResultSetMetaData resultMeta = result.getMetaData();
             int compteur=0;
             while(result.next()){
             compteur++;
             }
             result=state.executeQuery("select nbr_places_maximum from itineraire where id_itineraire="+itineraire);
             resultMeta=result.getMetaData();
             /*while(result.next()){         
             for(i = 1; i <= resultMeta.getColumnCount(); i++){
             int r=result.getInt(1);
             System.out.print("\t" + r+ "\t |");
             }
            
             System.out.println("\n---------------------------------");
       
             }
             if(result.next()){
             int r=result.getInt(1);
             if(compteur+1>r)continue;
             }
             Date date= Calendar.getInstance().getTime();
             state.execute("insert into reservation values ("+i+","+i+","+itineraire+");");*/
            /*int nomTvoie=new Random().nextInt(19)+1;
             int idH=new Random().nextInt(499)+1;
             int pDepart=new Random().nextInt(8)+1;
             int pArrivee=new Random().nextInt(8)+1;
             int cout=new Random().nextInt(200)+100;
             int nbrPlacesMax=new Random().nextInt(100)+50;
             state.execute("insert into itineraire values ("+i+","+nomTvoie+","+idH+","+pDepart+","+pArrivee+","+cout+","+nbrPlacesMax+");");
             *//*    
             int nombreDeplaces=new Random().nextInt(10);
             state.execute("insert into nomtvoie values ("+i+",\'"+i+"\',\'nomtvoie"+i+"\',"+nombreDeplaces+");");*/
            /*
             int jour= new Random().nextInt(360);
             int heure=new Random().nextInt(24);
             int minute=new Random().nextInt(60);
             state.execute("insert into horaire values ("+i+","+jour+","+heure+","+minute+");");*/
            //state.execute("insert into client values ("+i+",\'nom"+i+"\',\'prenom"+i+"\',\'adresse"+i+"\');");

            /*
             result=state.executeQuery("select * from horaire");
             ResultSetMetaData resultMeta = result.getMetaData();
             while(result.next()){         
             for(int i = 1; i <= resultMeta.getColumnCount(); i++)
             System.out.print("\t" + result.getObject(i).toString() + "\t |");
            
             System.out.println("\n---------------------------------");
       
             }
             }*/
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection connection = DriverManager.getConnection(
                    "jdbc:oracle:thin:@localhost:1521:XE", "SYSTEM",
                    "azerty00");
            Statement state = connection.createStatement();
            int i = 0;
            Random random = new Random();
            for (; i < 200; i++) {
                //int t1 = random.nextInt(i);
                String ville1 = "";
                String ville2 = "";
                int t2 = random.nextInt(5);
                int t3 = random.nextInt(1000);
                int prix = random.nextInt(100) + 100;
                switch (t2) {
                    case 0:
                        ville1 = "Alger";
                        break;
                    case 1:
                        ville1 = "Tlemcen";
                        break;
                    case 2:
                        ville1 = "Marseille";
                        break;
                    case 3:
                        ville1 = "Tanger";
                        break;
                    case 4:
                        ville1 = "Tetouane";
                        break;
                    case 5:
                        ville1 = "Montpellier";
                        break;
                }
                t2 = random.nextInt(5);
                switch (t2) {
                    case 0:
                        ville2 = "Alger";
                        break;
                    case 1:
                        ville2 = "Tlemcen";
                        break;
                    case 2:
                        ville2 = "Marseille";
                        break;
                    case 3:
                        ville2 = "Tanger";
                        break;
                    case 4:
                        ville2 = "Tetouane";
                        break;
                    case 5:
                        ville2 = "Montpellier";
                        break;
                }
                int jour = new Random().nextInt(360);
                int heure = new Random().nextInt(24);
                int minute = new Random().nextInt(60);
                int bateau=random.nextInt(200);
                if (ville1.equalsIgnoreCase(ville2)) {
                    continue;
                }
                String requete="INSERT INTO VOYAGE VALUES (\'" + i + "\',\'" + ville1 + "\',\'" + ville2 + "\'," + jour + "," + heure + "," + minute + ",T_BATEAU(" + t3 + ",\'Bateau" + bateau + "\')," + prix + ")";
                System.out.println("requete: "+requete);
                state.execute(requete);
            }
            state.executeQuery("");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
